<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * CIBlog
 *
 * 使用codeigniter框架开发的一个博客。
 * 
 * @package     ciblog
 * @author      Eric
 * @copyright   Copyright (c) 2011 - 2012, Eric
 * @license     GNU General Public License 2.0
 * @link        http://www.hebaijun.com
 * @version     1.0
 */

 //----------------------------------------------------------

 /**
  * 单页控制器
  *
  * 控制单页面的一些显示信息
  *
  * @package     ciblog
  * @subpackage  Controllers
  * @category    Controllers
  * @author      Eric <baijun.he@163.com>
  * @link        http://www.hebaijun.com
  */
class Page extends MY_Controller {

	/**
	 * 默认方法
	 *
	 * @access   public
	 * @return   void
	 */
	public function index($id = '', $comment_page = '1')
	{
		//取得ciblog的所有设置项
		$data['bloginfo'] = $this->option_m->load_all_options();

		//当前位置,用页面id，或者分类id判断
		$data['current_position'] = $id;

		//单页导航
		$menu_pages = $this->page_m->load_pages('post_id,post_title');
		$data['menu_pages'] = $menu_pages;
		
		//分类目录
		$menu_cat = $this->category_m->load_all_category('term_id,term_name,term_count');
		$data['menu_cat'] = $menu_cat;

		//随机文章
		$limit_random = $data['bloginfo']['home_random_view_num'];
		$home_random_view_array = array(
			'limit' => $limit_random,
			'orderby' => 'post_id',
			'order' => 'random'
		);
		$home_random_view_result = $this->post_m->load_posts('post_id,post_title',$home_random_view_array);
		$data['home_random_view'] = $home_random_view_result;

		//页面内容
		$page_search_array = array(
			'limit' => 1,
			'page_id' => $id
		);
		$page = $this->page_m->load_pages('*',$page_search_array);
		$data['post_result'] = $page[0];

		//标题
		$data['current_title'] = $page[0]->post_title;

		//评论分页
		$this->load->model('comment_m');
		$comment_limit = $data['bloginfo']['comment_per_post'];
		$config['base_url'] = base_url().'/page/'.$id.'/comment_pages/';
		$config['total_rows'] = $data['post_result']->post_comment_count;
		$config['per_page'] = $comment_limit; 
		$config['cur_page'] = $comment_page; 
		$this->pages->initialize($config); 
		$data['pagination'] = $this->pages->create_links();

		//取评论
		$comment_search_array = array(
			'comment_post_id' => $id,
			'limit' => $comment_limit,
			'offset' => $comment_limit*($comment_page-1),
			'comment_approved' => 1,
			'orderby' => 'comment_date',
			'order' => 'ASC'
		);
		$comments = $this->comment_m->load_comments('*',$comment_search_array);
		$data['comments'] = $comments;

		$this->theme_view('page', $data);
	}

}

/* End of file page.php */
/* Location: ./application/controllers/page.php */